/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package twitterWatchFollow;

import java.util.Calendar;

/**
 *
 * @author yos
 */
public class RetrySleepJDialog extends javax.swing.JDialog {
    private Calendar m_cal=Calendar.getInstance();
    private boolean m_isStop=false;
    private int m_sleepInSecond=-1;
    private final int m_ref_total_retry_count=++TwitterWatchFollow.m_total_retry_loop_count;

    /**
     * Creates new form RetrySleepJDialog
     */
    public RetrySleepJDialog(java.awt.Frame parent, boolean modal, int sleepInSecond) {
        super(parent, modal);
        initComponents();
        m_sleepInSecond=sleepInSecond;
        m_cal.add(Calendar.SECOND, m_sleepInSecond);
        updateMessage();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        stopjButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        TimerjLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        stopjButton.setText("Stop");
        stopjButton.setActionCommand("StopJButton");
        stopjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopjButtonActionPerformed(evt);
            }
        });

        jLabel1.setText("Wait Until");

        TimerjLabel.setText("9999");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(TimerjLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(126, 126, 126)
                        .addComponent(stopjButton)))
                .addContainerGap(133, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(TimerjLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(stopjButton)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void stopjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopjButtonActionPerformed
        m_isStop=true;
        setVisible(false);
    }//GEN-LAST:event_stopjButtonActionPerformed

    // accessor
    public final boolean isTimePassed(){
        boolean ret=m_cal.before(Calendar.getInstance());
        System.out.println("isTimePassed: return= "+ret);
        System.out.flush();
        return ret;
    }
    public final boolean isStop(){ return m_isStop;}
    //
    public final void updateMessage(){
        TimerjLabel.setText(String.format("%04d/%02d/%02d %02d:%02d:%02d  (loop_retry %d)",
                m_cal.get(Calendar.YEAR),m_cal.get(Calendar.MONTH)+1,m_cal.get(Calendar.DAY_OF_MONTH),
                m_cal.get(Calendar.HOUR_OF_DAY),m_cal.get(Calendar.MINUTE),m_cal.get(Calendar.SECOND),
                m_ref_total_retry_count));
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(RetrySleepJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(RetrySleepJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(RetrySleepJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(RetrySleepJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                RetrySleepJDialog dialog = new RetrySleepJDialog(new javax.swing.JFrame(), true, 30);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel TimerjLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton stopjButton;
    // End of variables declaration//GEN-END:variables
}
